package com.ruoyi.system.service;

import com.ruoyi.common.core.domain.zzw.CloseInfo;
import com.ruoyi.common.core.domain.zzw.CreateMeetingInfo;
import com.ruoyi.common.core.domain.zzw.KickInfo;
import com.ruoyi.common.core.domain.zzw.MeetingSet;
import com.xylink.model.CallInviteRequest;
import com.xylink.model.Device;
import com.xylink.model.MeetingInfo;
import com.xylink.sdk.SdkMethodV2;
import com.xylink.util.Result;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class MeetingControlApi {

    public Result inviteCall(String enterpriseId, CallInviteRequest sdkMeetingReq) throws IOException {
        String url = this.getPrefixUrl(enterpriseId) + "invitation?enterpriseId=" +enterpriseId;
        return SdkMethodV2.sdkPut(url,sdkMeetingReq,null);
    }

    private String getPrefixUrl(String enterpriseId) {
        return "/api/rest/external/v1/conferenceControl/";
    }

    public Result MeetingDelete(String enterpriseId, String callNumber) throws IOException {
        String url = "/api/rest/external/v1/meetingInfo/" + callNumber + "?enterpriseId=" +enterpriseId;
        return SdkMethodV2.sdkDelete(url,null);
    }

    public Result meetingCreate(CreateMeetingInfo reqJson) throws IOException {
        String url = "/api/rest/external/v1/create_meeting?enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293";
        return SdkMethodV2.sdkPost(url,reqJson, MeetingInfo.class);
    }

    public Result meetingHostSet(MeetingSet reqJson) throws IOException {
        String url = "/api/rest/external/v1/conferenceControl/meetingHostSet?enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293&callNumber=910011178334";
        return SdkMethodV2.sdkPost(url,reqJson,null);
    }

    public Result meetingQuery() throws IOException {
        String url = "/api/rest/external/v1/conferenceControl/910011178334/meetingStatus?enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293";
        return SdkMethodV2.sdkGet(url,null);
    }

    public Result MeetingStop(String callNumber) throws IOException {
        String url = "/api/rest/external/v1/conferenceControl/"+callNumber+"/end?enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293";
        return SdkMethodV2.sdkPut(url,null,null);
    }

    public Result disconnect(String callNumber, List<KickInfo> devicelist) throws IOException {
        String url = "/api/rest/external/v1/conferenceControl/"+callNumber+"/disconnect?enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293";
        return SdkMethodV2.sdkPut(url,devicelist,null);
    }

    public Result mute(boolean force,String callNumber, Device[] devices) throws IOException {
        String url = "/api/rest/external/v1/conferenceControl/"+callNumber+"/mute?force="+force+"&enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293";
        return SdkMethodV2.sdkPut(url,devices,null);
    }

    public Result closeCamera(CloseInfo closeInfo) throws IOException {
        String url = "/api/rest/external/v1/conferenceControl/meeting/video/operate?enterpriseId=ac0363b754a0afe5bd7378d81cff5e23a41ea293";
        return SdkMethodV2.sdkPost(url,closeInfo,null);
    }
}
